package Text_56;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Code {

	public static void main(String[] args) {
		Map<String,String> map = new HashMap<>();
        //put 添加/覆盖（返回覆盖的值）
        map.put("郭靖","黄蓉");
        map.put("杨过","小龙女");
        map.put("韦小宝","双二");
        //
        System.out.println(map);
        System.out.println(map.size());
        map.remove("韦小宝");
        System.out.println(map);

        //遍历
        //1.通过键找值
        //获取所有键，放入单列集合
        Set<String> keys = map.keySet();
        for(String i: keys){
            String value = map.get(i);
            System.out.println(i + "=" + value);
        }
        //2.通过键值对对象查找
        Set<Map.Entry<String, String>> entries = map.entrySet();
        //类型是Entry，并且是一个接口，用Map调用
        for(Map.Entry<String, String> entry:entries){
            //调用get方法获取键
            String key = entry.getKey();
            //调用get方法获取值
            String value = entry.getValue();
            System.out.println(key + "=" + value);

        }

	}

}
